﻿/**
  ******************************************************************************
  * @file    Libraries/Device/JS32T031/JS32T031_LL_Driver/inc/js32t031_ll_lcd.h
  * @author  JUSHENG Application Team
  * @version V1.0.0
  * @date    02-19-2022
  * @brief   This file contains all the LCD LL firmware functions.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 JUSHENG</center></h2>
  *
  *
  *
  ******************************************************************************
  */ 
  
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __JS32T031_LL_LCD_H
#define __JS32T031_LL_LCD_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "js32t031.h"
     
/** @addtogroup JS32T031_StdPeriph_Driver JS32T031 Driver
  * @{
  */
     
/** @addtogroup lcd_interface_gr LCD Driver
  * @ingroup  JS32T031_StdPeriph_Driver
  * @{
  */ 

/** @addtogroup LCD_LL_Driver LCD LL Driver
  * @ingroup  lcd_interface_gr
  * @brief Mainly the driver part of the LCD module, which includes \b LCD \b Register 
  * \b Constants, \b LCD \b Exported \b Constants, \b LCD \b Exported \b Struct, \b LCD
  * \b Data \b transfers \b functions, \b LCD \b Initialization \b and \b LCD \b Configuration 
  * \b And \b Interrupt \b Handle \b function.
  * @{
  */

/* Exported types ------------------------------------------------------------*/

/* Exported constants --------------------------------------------------------*/

/** @defgroup LCD_LL_Register_Constants LCD LL Register Constants
  * @ingroup  LCD_LL_Driver
  * @brief    LCD LL register constant table definition
  *
  *
@verbatim   
  ===============================================================================
                                Register Constants
  ===============================================================================  
  
    Register Constants mainly encapsulates each bit in each group in the LCD 
    register. In the process of configuration, the macro definition can be directly 
    called to configure the LCD register, mainly for convenience. Understand the 
    configuration of the LCD.
    
@endverbatim
  *
  * @{
  */

/***** LCD_CON Register *****/
/*! RW, LCD voltage selection  
 * VLCD=£¨17+LCD_VSEL)/32 *VCC  
 */
#define LL_LCD_CON_VOLTTAGE_SELCETION(n)                    (((n)&0xF) << 23)

/*! RW, LCD Analog drive enable  
 */
#define LL_LCD_CON_ANALOG_ENABLE                            (1UL << 22)

/*! RW, LCD Analog high level drive setting  
 */
#define LL_LCD_CON_ANALOG_HIGH_LEVEL_SET(n)                 (((n)&0x3) << 19)

/*! RW, LCD Analog low level drive setting  
 */
#define LL_LCD_CON_ANALOG_LOW_LEVEL_SET(n)                  (((n)&0x3) << 16)

/*! RW, LCD voltage test mode enable  
 */
#define LL_LCD_CON_TEST_MODE_EN                             (1UL << 6)

/*! RW, LCD test mode seg14 voltage output selectiong  
 * 1/2 bias mode  
 * 0: 0V  
 * 1: Reserved  
 * 2: 1/2V  
 * 3: 2/2V  
 * 1/3 bias mode  
 * 0: 0V  
 * 1: 1/3V  
 * 2: 2/3V  
 * 3: 3/3V  
 */
#define LL_LCD_CON_TEST_VOLTAGE_SET(n)                      (((n)&0x3) << 4)

/*! RW, LCD Scan frame interrupt enable  
 */
#define LL_LCD_CON_SCAN_FRAME_IE                            (1UL << 3)

/*! RW, LCD COM dynamic scan mode  
 * 0: ROM mode  
 * 1: FRAME mode  
 */
#define LL_LCD_CON_COM_SCAN_MODE                            (1UL << 2)

/*! RW, LCD COM, SEG Voltage offset mode  
 * 0: 1/3 bias mode  
 * 1: 1/2 bias mode  
 */
#define LL_LCD_CON_BIAS_TYPE                                (1UL << 1)

/*! RW, LCD Controller enable  
 */
#define LL_LCD_CON_LCD_EN                                   (1UL << 0)


/***** LCD_COM_NUM Register *****/
/*! RW, LCD COM number set  
 * 0£ºCOM=1  
 * 1£ºCOM=2  
 * 2£ºCOM=3  
 * 3£ºCOM=4  
 */
#define LL_LCD_COM_NUM_SET(n)                               (((n)&0x3) << 0)


/***** LCD_REFRESH Register *****/
/*! RW, LCD refresh pending  
 */
#define LL_LCD_REFRESH_PENDING                              (1UL << 0)


/***** LCD_DIV_CON Register *****/
/*! RW, LCD dead zone time control  
 * 0~255: dead zone time is LCD_DEAD_ZONE + 1 LCD_CLK clock  
 */
#define LL_LCD_DIV_CON_DEAD_ZONE(n)                         (((n)&0xFF) << 8)

/*! RW, LCD Each COM take time control  
 * 0~255: Each COM enable LCD_CLK_DIV + 1 LCD_CLK  
 */
#define LL_LCD_DIV_CON_CLK_DIV(n)                           (((n)&0xFF) << 0)


/***** LCD_COM_SEG_ENA Register *****/
/*! RW, LCD 8 COM ports enable control  
 * NOTE: 8 COM ports can only choose 4 at most  
 * 0: disable  
 * 1: enable   
 */
#define LL_COM_EN(n)                                        (((n)&0xFF) << 22)

/*! RW, LCD 18 SEG port enable control  
 * 0: disable  
 * 1: enable   
 */
#define LL_SEG_EN(n)                                        (((n)&0x3FFFFF) << 0)


/***** LCD_COM Register *****/
/*! RW, LCD 18-bit SEG port data corresponding to COM port  
 */
#define LL_LCD_COM_SEG_DATA(n)                              (((n)&0x3FFFFF) << 0)


/***** LCD_STA Register *****/
/*! RC, LCD Scan frame interrupt pending  
 */
#define LL_LCD_STA_SCAN_FRAME_PINDING                       (1UL << 0)

/**
  * @}
  */

/** @defgroup LCD_LL_Exported_Constants LCD LL Exported Constants
  * @ingroup  LCD_LL_Driver
  * @brief    LCD LL external constant definition
  *
@verbatim   
  ===============================================================================
                                Exported Constants
  ===============================================================================  
  
    Exported Constants mainly restricts the partial configuration of the abstraction 
    layer by using the form of enumeration to facilitate the use and understanding of 
    the module configuration. For the specific enumeration meaning, please refer to 
    the annotation of each module.

@endverbatim
  *
  * @{
  */
  
/***** DRIVER API *****/


/***** LL API *****/

/**
  * @brief Enumeration constant for the lcd COM dynamic scan mode
  */
typedef enum {
    /*! ROM scan mode  
     */
    LL_LCD_COM_SCAN_ROM         = 0,
    /*! FRAME scan mode  
     */
    LL_LCD_COM_SCAN_FRAME       = 1,
} TYPE_ENUM_LL_LCD_COM_SCAN;

/**
  * @brief Enumeration constant for the LCD COM, SEG voltage offset mode
  */
typedef enum {
    /*! 1/3 bias mode  
     */
    LL_LCD_BIAS_1_3_MODE        = 0,
    /*! 1/2 bias mode  
     */
    LL_LCD_BIAS_1_2_MODE        = 1,
} TYPE_ENUM_LL_LCD_BIAS_TYPE;

/**
  * @brief Enumeration constant for the LCD duty type
  */
typedef enum {
    /*! 1/1 duty mode  
     */
    LL_LCD_DUTY_1_1_MODE        = 0,
    /*! 1/2 duty mode  
     */
    LL_LCD_DUTY_1_2_MODE        = 1,
    /*! 1/3 duty mode  
     */
    LL_LCD_DUTY_1_3_MODE        = 2,
    /*! 1/4 duty mode  
     */
    LL_LCD_DUTY_1_4_MODE        = 3,
} TYPE_ENUM_LL_LCD_DUTY_TYPE;

/**
  * @brief Enumeration constant for the LCD voltage type, VLCD=£¨17+LCD_VSEL)/32 *VCC
  */
typedef enum {
    /*! VCC is 3V, LCD is 3V  
     */
    LL_LCD_VCC_3V_LCD_3V        = 15,
    /*! VCC is 5V, LCD is 3V  
     */
    LL_LCD_VCC_5V_LCD_3V        = 2,
    /*! VCC is 5V, LCD is 5V  
     */
    LL_LCD_VCC_5V_LCD_5V        = 15,
} TYPE_ENUM_LL_LCD_VOLTAGE_TYPE;


/**
  * @}
  */

/** @defgroup LCD_LL_Exported_Struct LCD LL Exported Struct
  * @ingroup  LCD_LL_Driver
  * @brief    LCD LL external configuration structure definition
  *
@verbatim   
  ===============================================================================
                                Exported Struct
  ===============================================================================  

    Exported Struct mainly extracts the LCD registers from the API, and abstracts 
    the structure. As long as it implements the low coupling between the registers 
    and the registers, the user only needs to configure the structure of the abstraction 
    layer and call hal_lcd_init. Function, you can configure the LCD module without 
    involving the configuration of the collective register.

@endverbatim
  *
  * @{
  */

/**
  * @brief LCD low layer initialization struct
  */
typedef struct __ll_lcd_init {
    /*! LCD COM scan  
     */
    TYPE_ENUM_LL_LCD_COM_SCAN           com_scan;
    /*! LCD bias type  
     */
    TYPE_ENUM_LL_LCD_BIAS_TYPE          bias_type;
    /*! LCD duty type  
     */
    TYPE_ENUM_LL_LCD_DUTY_TYPE          duty_type;
    /*! LCD voltage type  
     * VLCD=£¨17+LCD_VSEL)/32 *VCC
     */
    TYPE_ENUM_LL_LCD_VOLTAGE_TYPE       voltage_type;
    /*! LCD Each COM take time control  
     * 0~255: Each COM enable LCD_CLK_DIV + 1 LCD_CLK  
     */
    u8                                  com_clk;
    /*! LCD 8 COM ports enable control  
     * NOTE: 8 COM ports can only choose 4 at most  
     */
    u8                                  com_en;
    /*! LCD 18 SEG port enable control  
     */
    u32                                 seg_en;
} TYPE_LL_LCD_INIT;

/**
  * @}
  */

/** @defgroup LCD_LL_Interrupt LCD LL Interrupt Handle function
  * @brief   LCD LL Interrupt Handle function
  *
@verbatim   
  ===============================================================================
                        Interrupt Handle function
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the WDT  
    Interrupt Handle function.

    how to use?

    The LCD interrupt handler uses a callback method that reserves the interface 
    to the user in the form of a callback function. The client needs to initialize 
    the callback function when initializing the LCD in order for the interrupt to 
    be processed normally. 
   
@endverbatim
  *
  * @{
  */



/**
  * @}
  */
  
/** @defgroup LCD_LL_Inti_Cfg LCD LL Initialization And Configuration
  * @brief    LCD LL Initialization And Configuration
  *
@verbatim   
  ===============================================================================
                        Initialization And Configuration
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the LCD data 
    Initialization and Configuration.
    
    how to use?

@endverbatim
  *
  * @{
  */

/**
  * @brief  lcd_init
  * @param  p_lcd : pointer to the hardware LCD_TypeDef
  * @param  p_init: pointer to the init stuct TYPE_LL_LCD_INIT
  * @retval None
  */
void ll_lcd_init(LCD_TypeDef *p_lcd,TYPE_LL_LCD_INIT *p_init);

/**
  * @}
  */
  
/** @defgroup LCD_LL_Data_Transfers LCD LL Data transfers functions
  * @brief    LCD LL Data transfers functions 
  *
@verbatim   
  ===============================================================================
                            Data transfers functions
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the LCD data 
    transfers and receive.
  
@endverbatim
  *
  * @{
  */

/**
  * @brief  LCD Controller enable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_controller_enable(LCD_TypeDef *p_lcd);
/**
  * @brief  LCD Controller disable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_controller_disable(LCD_TypeDef *p_lcd);
/**
  * @brief  LCD Controller enable get
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval result
  */
#define LL_LCD_CON_LCD_CONT_EN_GET(p_lcd)                   ((p_lcd)->LCD_CON & LL_LCD_CON_LCD_EN)

/**
  * @brief  LCD analog drive enable enable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_analog_enable(LCD_TypeDef *p_lcd);
/**
  * @brief  LCD analog drive enable disable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_analog_disable(LCD_TypeDef *p_lcd);
/**
  * @brief  LCD analog drive enable get
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval result
  */
#define LL_LCD_CON_ANALOG_EN_GET(p_lcd)                     ((p_lcd)->LCD_CON & LL_LCD_CON_ANALOG_ENABLE)

/**
  * @brief  LCD test mode enable get
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval result
  */
#define LL_LCD_CON_TEST_MODE_EN_GET(p_lcd)                  ((p_lcd)->LCD_CON & LL_LCD_CON_TEST_MODE_EN)

/**
  * @brief  LCD scan frame interrupt enable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_scan_frame_interrupt_enable(LCD_TypeDef *p_lcd);
/**
  * @brief  LCD scan frame interrupt disable
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
void ll_lcd_scan_frame_interrupt_disable(LCD_TypeDef *p_lcd);
/**
  * @brief  LCD frame interrupt enable get
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval result
  */
#define LL_LCD_CON_LCD_SCAN_FRAME_INTERRUPT_EN_GET(p_lcd)   ((p_lcd)->LCD_CON & LL_LCD_CON_SCAN_FRAME_IE)

/**
  * @brief  LCD dead zone time control set
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @param  val: dead time, 0~255
  * @retval none
  */
void ll_lcd_div_dead_time_set(LCD_TypeDef *p_lcd, u8 val);

/**
  * @brief  LCD Each COM take time control
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @param  val: frame rate, 0~255
  * @retval none
  */
void ll_lcd_clk_div_set(LCD_TypeDef *p_lcd, u8 val);

/**
  * @brief  LCD COM port 18-bit SEG data set
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @param  com_num: COM port num, COM0 - COM3
  * @param  data: high 18-bit SEG data
  * @retval none
  */
void ll_lcd_com_seg_set(LCD_TypeDef *p_lcd, u8 com_num, u32 data);

/**
  * @brief  LCD COM port 18-bit SEG data get
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @param  com_num: COM port num, COM0 - COM3
  * @param  data: high 18-bit SEG data
  * @retval none
  */
void ll_lcd_com_seg_get(LCD_TypeDef *p_lcd, u8 com_num, u32 *data);

/**
  * @brief  LCD refresh pending
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
#define LL_LCD_REFRESH_PENDING_SET(p_lcd)                   ((p_lcd)->LCD_REFRESH |= LL_LCD_REFRESH_PENDING)
/**
  * @brief  LCD refresh pending get
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
#define LL_LCD_REFRESH_PENDING_GET(p_lcd)                   ((p_lcd)->LCD_REFRESH & LL_LCD_REFRESH_PENDING)

/**
  * @brief  LCD frame interrupt pending get
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
#define LL_LCD_STA_SCAN_FRAME_PINDING_GET(p_lcd)            ((p_lcd)->LCD_STA & LL_LCD_STA_SCAN_FRAME_PINDING)
/**
  * @brief  LCD frame interrupt pending clear
  * @param  p_lcd: pointer to the hardware LCD_TypeDef
  * @retval none
  */
#define LL_LCD_STA_SCAN_FRAME_PINDING_CLR(p_lcd)            ((p_lcd)->LCD_STA = LL_LCD_STA_SCAN_FRAME_PINDING)

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

/**
  * @}
  */

/**
  * @}
  */

#endif //__JS32T031_LL_LCD_H

/*************************** (C) COPYRIGHT 2022 JUSHENG ***** END OF FILE *****/
